package com.lysj.order.order.repository;

import com.lysj.admin.utils.spring.foundation.base.BaseRepository;
import com.lysj.order.order.domain.OrderItem;
import com.lysj.order.order.vo.WorkBenchOrderItemVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

/**
 * @author Created by drj on 2019-03-13 10:43:06
 * @description 订单详情dao
 */
public interface OrderItemRepository extends BaseRepository<OrderItem> {

    //显示订单详情使用
    List<OrderItem> findByOrderIdAndDelFlag(String orderId, Integer deflag);

    //点餐进度(已点菜、已赠菜)
    @Query(value = "SELECT NEW com.lysj.order.order.vo.WorkBenchOrderItemVo(o.id,o.name,o.amount,o.specifications,o.doWay,o.unitPrice,o.tolPrice) " +
            "FROM  OrderItem o WHERE  o.orderId=?1 AND o.status=?2 AND o.delFlag=1")
    Page<WorkBenchOrderItemVo> findByOrderIdAndStatus(Pageable pageable, String orderId, Integer status);

    //统计子单中不同菜品类别数量
    Integer countByOrderIdAndStatusAndDelFlag(String orderId, Integer status, Integer deflag);

    //计算订单的售价(已点菜跟茶座费)
    @Query(value = "SELECT  SUM(tol_price) FROM lysj_order_order_item WHERE order_id=?1 AND status in (1,4) AND del_flag=1", nativeQuery = true)
    BigDecimal summaryMoney(String orderId);

    //计算点菜数量(点菜跟赠菜)
    @Query(value = "select  count(*) from lysj_order_order_item where order_id=?1 AND status in (1,2) AND del_flag=1 ", nativeQuery = true)
    BigInteger countFood(String orderId);

    List<OrderItem> findByOrderIdAndStatusAndDelFlag(String orderId, Integer status, Integer delFlag);
}